/*
 * @Description:
 * @Author: Dxcr
 * @Date: 2025-01-15 09:53:10
 * @LastEditTime: 2025-01-15 16:08:20
 * @LastEditors: Dxcr
 */
mod mqtt_client;
mod config_loader;

use mqtt_client::MqttClient;
use config_loader::Config;

const MQTT_ID: &str = "rust_client_subscriber";

#[tokio::main]
async fn main() {
    // 从配置文件加载配置
    let config = Config::load("config.json");

    let mqtt_id: &str = MQTT_ID;
    let mqtt_broker = config.mqtt_broker;
    let mqtt_port = config.mqtt_port;
    let mqtt_username = config.mqtt_username;
    let mqtt_password = config.mqtt_password;

    let mqtt_publisher = MqttClient::new(
        mqtt_id,
        &mqtt_broker,
        mqtt_port,
        &mqtt_username,
        &mqtt_password,
    );

    mqtt_publisher
        .subscribe("WellsiteInformation", |_, _| {})
        .await;
    mqtt_publisher.subscribe("StageJobData", |_, _| {}).await;

    // 防止主线程退出
    loop {
        std::thread::sleep(std::time::Duration::from_secs(60));
    }
}
